package  
{
	import flash.events.MouseEvent;
	import flash.text.TextField;
	/**
	 * ...
	 * @author patsup
	 * 
	 * 		This class is a display (Button) that pops up at the end of a round. It needs
	 * 	to talk to the game's SessionStats to get how much was won or lost.
	 * 
	 * *** protected functions
	 * 
	 * DisplayImage(roundWon:int):void
	 * InputMouseClick(e:MouseEvent):void
	 * 
	 */
	public class RoundEnd extends Button 
	{
		//end of round image parameters
		private const RE_COLOR:int = 0x800080;
		private const RE_ALPHA:Number = 0.3;
		private const RE_WIDTH:int = 300;
		private const RE_HEIGHT:int = 80;
		
		private var btnLabel:TextField;			//label "game won" or "game lost"
		
		private var gameRef:PGame;
		
		public function RoundEnd(gameRef:PGame, roundWon:int, xCoord:int, yCoord:int) 
		{
			name = "Round End";
			this.gameRef = gameRef;
			btnLabel = new TextField();
			super(xCoord, yCoord);
			
			DisplayImage(roundWon);
			EnableButton();
		}
		
		//DisplayImage()
		//Initializes the image of the RoundEnd button
		protected function DisplayImage(roundWon:int):void
		{
			graphics.beginFill(RE_COLOR, RE_ALPHA);
			graphics.drawRect(0, 0, RE_WIDTH, RE_HEIGHT);
			graphics.endFill();
			
			if (roundWon) {
				btnLabel.text = "YAR! click to play again.\nYou scored " + String(gameRef.GetRoundScore() + "!!!");
			} else {
				btnLabel.text = "GAH! click to play again.\nYou scored " + String(gameRef.GetRoundScore() + "!!!");
			}
			
			var _winnings:int = gameRef.GetSS().CalcWinningsWithBetAndScore();
			var _betSize:int = gameRef.GetSS().GetCurrentBetSize();
			if (_winnings > 0) {
				btnLabel.appendText("\nYou won $" + _winnings);
			} else if (_winnings == 0) {
				btnLabel.appendText("\nYou broke even!" );
			} else {
				btnLabel.appendText("\nWow you did pretty bad... \n\tAND you lost your damn bet which was obviously $" + _betSize );
			}
			
			btnLabel.width = btnLabel.textWidth*1.0;			//reduce the textfield's dimensions so they don't inflate the stage
			btnLabel.height = btnLabel.textHeight*1.2;
			btnLabel.x = 0.5 * RE_WIDTH - 0.5 * btnLabel.width;
			btnLabel.y = 0.5 * RE_HEIGHT - 0.5 * btnLabel.height;
			addChild(btnLabel);									//now add this txt label to the display list
			
			super.InitImage();
		}
		
		//InputMouseClick()
		//Takes action for RoundEnd upon hearing the mouseclick event
		protected override function InputMouseClick(e:MouseEvent):void
		{
			gameRef.CleanUpRound();
			
			super.InputMouseClick(e);
		}
	}

}